//
//  ViewController.m
//  CustomDemo
//
//  Created by 于洪东 on 16/6/23.
//  Copyright © 2016年 于洪东. All rights reserved.
//

#import "ViewController.h"
#import "FirstViewController.h"

#import "CustomNaviBarSearchController.h"


@interface ViewController ()<CustomNaviBarSearchControllerDelegate>

@property (nonatomic,strong) CustomNaviBarSearchController *search;

@property (nonatomic,strong) NSMutableArray *searchKeyWordArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUI];
    [self initSearchUI];
    self.searchKeyWordArray = [NSMutableArray array];

}

-(void)rightButtonClick:(UIButton *)sender{
    NSLog(@"ViewController 子类中:ViewController");
    FirstViewController *first = [[FirstViewController alloc]init];
    [self.navigationController pushViewController:first animated:YES];

}

#pragma mark - 私有方法
-(void)initUI{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 200, 130, 30);
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(rightButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

-(void)initSearchUI{
    _search = [[CustomNaviBarSearchController alloc]initWithParentViewCtrl:self];
    _search.delegate = self;
    [_search resetPlaceHolder:@"去你妹的"];
    [_search setRecentKeyword:self.searchKeyWordArray];
    /**
     *  导航栏的类型，这句话必须要有
     */
    [_search showFixationSearchCtrl];
}


#pragma mark - 协议方法   ------ CustomNaviBarSearchControllerDelegate

-(void)naviBarSearchCtrlCancel:(CustomNaviBarSearchController *)ctrl{
    NSLog(@"取消按钮点击的协议");
}

-(void)naviBarSearchCtrl:(CustomNaviBarSearchController *)ctrl searchKeyword:(NSString *)strKeyword{
    NSLog(@".....%@",strKeyword);
    [self.searchKeyWordArray addObject:strKeyword];
    [_search setRecentKeyword:self.searchKeyWordArray];
    
}

-(void)naviBarSearchCtrlClearKeywordRecord:(CustomNaviBarSearchController *)ctrl{
    [_search setRecentKeyword:nil];
    [self.searchKeyWordArray removeAllObjects];
}




@end
